{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As previously introduced, the cross product takes two 3D vectors u and v as inputs, and its output u × v is another 3D vector. It is similar to the dot product in that the lengths and relative directions of the input vectors determine the output, but is different in that the output has not only a magnitude but also a direction."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# The right-hand rule"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/9.theRightHandRule.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you point your right index finger along the positive x-axis and curl your remaining fingers toward the positive y-axis, your thumb tells you the direction of the positive z-axis.\n",
    "\n",
    "This is called the right-hand rule, and if it agrees with your axes, then you are (correctly!) using the right-handed orientation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Finding the direction of the cross product"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Given two input vectors, the cross product outputs a result that is perpendicular to both. \n",
    "\n",
    "For instance, if u = (1,0,0) and v = (0,1,0), then it happens that the cross product u × v is (0, 0, 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/10.crossProductResultsPerpendicularVector.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Finding the length of the cross product"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/11.theLengthOfCrossProduct.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There’s a trigonometric formula for the area of this parallelogram: if u and v are separated by an angle $\\theta$ , the area is:\n",
    "\n",
    "$\n",
    "|u| · |v| · sin( \\theta )\n",
    "$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Computing the cross product of 3D vectors"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we have $u = (u_x, u_y, u_z)$ and $v=(v_x,v_y,v_z)$ \n",
    "\n",
    "$u \\times v = (u_y v_z - u_z v_y, u_z v_x-u_x v_z, u_x v_y - u_y v_x)$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This algebraic procedure agrees with the geometric description we built in this chapter. Because it tells us area and direction, the cross product helps us decide whether an occupant of 3D space would see a polygon floating in space with them. For instance, as figure 3.39 shows, an observer standing on the x-axis would not see the parallelogram spanned by u = (1, 1, 0) and v = (–2, 1, 0).\n",
    "\n",
    "In other words, the polygon in figure 3.39 is parallel to the observer’s line of sight. Using the cross product, we could tell this without drawing the picture. Because the cross product is perpendicular to the person’s line of sight, none of the polygon is visible.\n",
    "\n",
    "Now it’s time for our culminating project: building a 3D object out of polygons and drawing it on a 2D canvas. You’ll use all of the vector operations you’ve seen so far. In particular, the cross product will help you to decide which polygons are visible."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/12.useCrossProductToIndicateVisibility.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> yingshaoxo: That's why GPU was used to do machine learning. The 3D game needs to convert 3D to 2D to be able to let the user see. That conversation was based on vector computation. Deep learning also relies on vector computations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercise 3.23"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/13.exercise3.23.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Excercise 3.24"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![image.png](images/14.exercise3.24.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "So you should at least remember an empty model of 3D coordinates to be able to solve the above problem."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercise 3.25"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use the Python cross function to compute (0, 0, 1) × v for a few different values of a second vector v. What is the z-coordinate of each result, and why?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "No matter what vector v is chosen, the z-coordinate is zero.\n",
    "\n",
    "Geometrically this makes sense: the cross product should be perpendicular to both inputs, and to be perpendicular to (0, 0, 1), the z component must be zero."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
